package com.sharer.last.controller;

import com.sharer.last.annotation.AccessLimit;
import com.sharer.last.annotation.VisitLogger;
import com.sharer.last.base.constant.CommonConstant;
import com.sharer.last.base.model.PageVO;
import com.sharer.last.base.model.R;
import com.sharer.last.enums.VisitBehavior;
import com.sharer.last.model.dto.moment.MomentQueryDTO;
import com.sharer.last.model.vo.moment.MomentVO;
import com.sharer.last.service.MomentService;
import com.sharer.last.service.impl.UserServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 动态前端控制器
 *
 * @ClassName MomentController
 * @Author wangjin
 * @Date 2023/5/5 21:07
 * @Description
 * @Version 1.0
 */
@RestController
@RequestMapping(CommonConstant.BLOG_FRONT_API + "/moment")
public class MomentController {
	@Resource
	MomentService momentService;
	@Resource
	UserServiceImpl userService;

	/**
	 * 分页查询动态List
	 *
	 * @param momentDTO
	 * @return
	 */
	@VisitLogger(VisitBehavior.MOMENT)
	@PostMapping("/selectByPage")
	public R<PageVO<MomentVO>> moments(@RequestBody MomentQueryDTO momentDTO) {
		PageVO<MomentVO> pageList = momentService.selectListByPage(momentDTO);
		return R.success(pageList);
	}

	/**
	 * 给动态点赞
	 * 简单限制一下点赞
	 *
	 * @param id 动态id
	 * @return
	 */
	@AccessLimit(seconds = 86400, maxCount = 1, msg = "不可以重复点赞哦")
	@VisitLogger(VisitBehavior.LIKE_MOMENT)
	@GetMapping("/like/{id}")
	public R like(@PathVariable Long id) {
		momentService.addLikeByMomentId(id);
		return R.handle();
	}
}
